package com.dingreading.cloud.web.service.impl;

import com.dingreading.cloud.common.util.DateUtil;
import com.dingreading.cloud.web.entity.StudyVideoLog;
import com.dingreading.cloud.web.entity.table.StudyVideoLogTableDef;
import com.dingreading.cloud.web.mapper.StudyVideoLogMapper;
import com.dingreading.cloud.web.service.StudyVideoLogService;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2025-09-17
 */
@Service
public class StudyVideoLogServiceImpl extends BaseServiceImpl<StudyVideoLogMapper, StudyVideoLog, StudyVideoLogTableDef> implements StudyVideoLogService {

    @Override
    protected StudyVideoLogTableDef getTable() {
        return StudyVideoLogTableDef.studyVideoLog;
    }

    @Override
    public long todayViewCount(String uid, String ip) {
        String today = DateUtil.getNowDateStr();
        QueryCondition condition = table.videoUid.eq(uid)
                .and(table.ip.eq(ip))
                .and(table.addTime.likeLeft(today));
        QueryWrapper wrapper = QueryWrapper.create()
                .select(table.id)
                .from(table)
                .where(condition);
        return getMapper().selectCountByQuery(wrapper);
    }
}
